package com.example.customview.behavior

import android.util.Log
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.android.baselibrary.base.BaseFragment
import com.android.baselibrary.utils.ScreenUtils
import com.android.baselibrary.utils.dp2px
import com.example.customview.R
import com.example.customview.arouter.CustomArouter
import com.example.customview.databinding.FragmentBehaviorBinding
import com.google.android.material.bottomsheet.BottomSheetBehavior
@Route(path = CustomArouter.CUSTOM_BEHAVIOR_VIEW)
class BehaviorFragment:BaseFragment<FragmentBehaviorBinding>() {
    override fun getLayoutID()= R.layout.fragment_behavior

    private var mBehaviorHeight = 0
    override fun initView() {

        val screenHeight = ScreenUtils.getHeight(requireContext())
        mBehaviorHeight = screenHeight - dp2px(requireContext(), 244)
        val layoutParams = mBinding.coordinatorContainer.layoutParams
        layoutParams.height = mBehaviorHeight
        mBinding.coordinatorContainer.layoutParams = layoutParams
        val bottomSheetBehavior =   BottomSheetBehavior.from(mBinding.col)
        bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
        bottomSheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback(){
            override fun onStateChanged(bottomSheet: View, newState: Int) {

            }

            override fun onSlide(bottomSheet: View, slideOffset: Float) {
                Log.i("TAG231", "onSlide:$slideOffset --${bottomSheet.height} ")
                val offsetY =
                    (mBehaviorHeight - dp2px(requireContext(), 94)) * (1 - slideOffset)
                val params = mBinding.topLl.layoutParams
                params.height = (dp2px(requireContext(), 210) + offsetY).toInt()
                mBinding.topLl.layoutParams = params

            }
        })

        val adapter = TestAdapter()
        mBinding.llBottom.adapter =adapter
        val data = mutableListOf<String>()
        for (i in 0..40){
            data.add("第$i")
        }
        adapter.setData(data)
        val rightadapter = TestAdapter()
        mBinding.rightBottom.adapter = rightadapter
        rightadapter.setData(data)
        mBinding.rightBottom.isNestedScrollingEnabled = false

    }
}